//
//  SQLiteHandler.h
//  PeopleLog
//
//  Created by Justin Kim on 11. 6. 16..
//  Copyright 2011 Daum. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "FMDatabase.h"
//#import "SingletonManager.h"
//#import "ValueObject.h"
//#import "ItemGroup.h"
//#import "Item.h"
//#import "Shop.h"
//#import "Bank.h"
//#import "Card.h"
//#import "Tag.h"
//#import "Write.h"

enum {
    DB_ACT_INSERT,
    DB_ACT_SELECT_BY_ID,
    DB_ACT_SELECT,
    DB_ACT_UPDATE,
    DB_ACT_DELETE
};
typedef NSUInteger DataBaseAction;

enum {
    DB_FUN_ACT_MAX,
    DB_FUN_ACT_MIN,
    DB_FUN_ACT_SUM,
    DB_FUN_ACT_COUNT
};
typedef NSUInteger DataFunctionAction;



@interface SQLHandler : NSObject {
    FMDatabase* _db;
}

@property(nonatomic, assign) FMDatabase* db;

+(SQLHandler *)sharedInstance;
- (void)updateOrder:(NSString*)tableName pkId:(NSNumber*)pkId order:(NSNumber*)order;
// ItemGroup
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createItemGroupWithTitle:(NSString*)title 
                           isIn:(NSString*)isIn;
- (NSDictionary*)findItemGroupById:(NSNumber*)itemGroupId;
- (NSArray*)findAllItemGroupByIsIn:(NSString*)isIn;
- (NSArray*)findAllItemGroup;
- (void)updateItemGroupId:(NSNumber*)itemGroupId
                    title:(NSString*)title 
                     isin:(NSString*)isIn;
- (void)deleteItemGroupById:(NSNumber*)itemGroupId;
// Item
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createItemWithItemGroupId:(NSNumber*)itemGroupId
                           title:(NSString*)title;
- (NSDictionary*)findItemById:(NSNumber*)itemId;
- (NSArray*)findAllItemByItemGroupById:(NSNumber*)itemGroupId;
- (void)updateItemId:(NSNumber*)itemId
               title:(NSString*)title;
- (void)deleteItemById:(NSNumber*)itemId;
// Shop
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createShopWithTitle:(NSString*)title;
- (NSDictionary*)findShopById:(NSNumber*)shopId;
- (NSArray*)findAllShop;
- (void)updateShopId:(NSNumber*)shopId
               title:(NSString*)title;
- (void)deleteShopById:(NSNumber*)shopId;

// Cash
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createCashWithTitle:(NSString*)title 
                 isDefault:(BOOL)isDefault;
- (NSDictionary*)findDefaultCash;
- (NSDictionary*)findCashById:(NSNumber*)cashId;
- (NSArray*)findAllCash;
- (void)updateCashId:(NSNumber*)cashId
               title:(NSString*)title
           isDefault:(BOOL)isDefault;
- (void)deleteCashById:(NSNumber*)cashId;

// Card
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createCardIdWithTitle:(NSString*)title 
                      bankId:(NSNumber*)bankId
                    startDay:(NSNumber*)startDay
                      endDay:(NSNumber*)endDay
                      payDay:(NSNumber*)payDay
                     isCheck:(BOOL)isCheck;
- (NSDictionary*)findCardById:(NSNumber*)cardId;
- (NSArray*)findAllCard;
- (void)updateCardId:(NSNumber*)cardId
               title:(NSString*)title
              bankId:(NSNumber*)bankId
            startDay:(NSNumber*)startDay
              endDay:(NSNumber*)endDay
              payDay:(NSNumber*)payDay
             isCheck:(BOOL)isCheck;
- (void)deleteCardById:(NSNumber*)cardId;


// Bank
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createBankWithTitle:(NSString*)title 
                      type:(NSNumber*)type;
- (NSDictionary*)findBankById:(NSNumber*)bankId;
- (NSArray*)findAllBank;
- (void)updateBankId:(NSNumber*)bankId
               title:(NSString*)title
                type:(NSNumber*)type;
- (void)deleteBankById:(NSNumber*)bankId;



// Tag
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createTagWithTitle:(NSString*)title;
- (NSDictionary*)findTagById:(NSNumber*)tagId;
- (NSArray*)findAllTag;
- (NSArray*)findallByWriteId:(NSNumber*)writeId;
- (void)createTagMappingWithTagId:(NSNumber*)tagId
                          writeId:(NSNumber*)writeId;
- (void)updateTagId:(NSNumber*)tagId
              title:(NSString*)title;
- (void)deleteTagById:(NSNumber*)tagId;

// Write
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- (int)createWriteWithItemGruopId:(NSNumber*)itemGroupId
                           itemId:(NSNumber*)itemId
                            title:(NSString*)title 
                          account:(NSNumber*)account
                           shopId:(NSNumber*)shopId
                           cashId:(NSNumber*)cashId
                           bankId:(NSNumber*)bankId
                           cardId:(NSNumber*)cardId
                         writeDay:(NSNumber*)writeDay
                    repeatWriteid:(NSNumber*)repeatWirteId
                           status:(NSString*)status;
- (NSDictionary*)findWriteById:(NSNumber*)writeId;
- (NSArray*)findAllWriteByStartDay:(NSNumber*)startDay endDay:(NSNumber*)endDay;




@end
